<?php


namespace app\btApi\controller;

use app\btApi\validate\LoginValidate;
use app\common\exception\BusinessException;
use app\common\exception\BusinessExceptionEnum;
use app\common\service\AdminService;
use app\common\utils\ExcelUtils;
use app\common\utils\ResponseUtils;
use app\common\utils\TokenUtils;
use app\common\utils\UploadUtils;
use think\facade\Request;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("登录相关")
 */
class Admin
{
    private $adminService;
    public function __construct()
    {
        $this->adminService=new AdminService();
    }

    /**
     * @Apidoc\Title("登录接口")
     * @Apidoc\Desc("这里是一个描述")
     * @Apidoc\Url("btApi/admin/login")
     * @Apidoc\Method("POST")
     * @Apidoc\Tag("登录")
     * @Apidoc\Param("username", type="string",require=true, desc="用户名" )
     * @Apidoc\Param("password",type="string",require=true,desc="用户密码")
     * @Apidoc\Returned("data", type="array", desc="数据",
     *    @Apidoc\Returned("token", type="string", desc="登录身份令牌")
     * )
     */
    public function login(){
        try {
            validate(LoginValidate::class)->check(Request::param());
            $data=$this->adminService->selectLogin(Request::post('username'),Request::post('password'));
            return ResponseUtils::retSuccessWithData($data);
        }catch (\Exception $exception){
            return ResponseUtils::retError($exception->getMessage());
        }
    }
    /**
     * @Apidoc\Title("获取所有用户")
     * @Apidoc\Desc("这里是一个描述")
     * @Apidoc\Url("btApi/admin/getuser")
     * @Apidoc\Method("POST")
     * @Apidoc\Tag("获取用户列表")
     * @Apidoc\Param("token", type="string",require=true, desc="用户名" )
     * @Apidoc\Param("password",type="string",require=true,desc="用户密码")
     * @Apidoc\Returned("data", type="array", desc="数据",
     *    @Apidoc\Returned("token", type="string", desc="登录身份令牌")
     * )
     */
    public function getuser(){
       $list=$this->adminService->selectList();
       return ResponseUtils::retSuccessWithData($list);
    }
    /**
     * @Apidoc\Title("上传图片")
     * @Apidoc\Desc("这里是一个描述")
     * @Apidoc\Url("btApi/admin/uploadFile")
     * @Apidoc\Method("POST")
     * @Apidoc\Tag("上传")
     * @Apidoc\Param("file", type="file",require=true, desc="文件" )
     */
    public function uploadFile(){
        $data=UploadUtils::thumbupload(request()->file('file'));
        return ResponseUtils::retSuccessWithData($data);
    }
    public function uploadExcel(){
        $data=ExcelUtils::shibie(request()->file('file'));
        return ResponseUtils::retSuccessWithData($data);
    }
}